package Model;

import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

public class displayHealth {
     private int health;
     private BufferedImage healthSpriteSheet;
     private BufferedImage currentHealth1;
     private BufferedImage currentHealth2;
    /// private int aniNumber;
     private int startXPos;
     private int startYPos;
     private GameBoard currentGameboard;
     public displayHealth(GameBoard currentGameboard){
    	/// aniNumber = 0;
    	 try{
    		 healthSpriteSheet = ImageIO.read(new File("C:/Users/Yan/workspace/mmbn/mmbn/src/Img/healthnumsV2.png"));
    	 }catch(IOException e){
    		 e.printStackTrace();
    	 }
    	 currentHealth1 = healthSpriteSheet.getSubimage(0 *8 , 0, 8, 13);
    	 currentHealth2 = healthSpriteSheet.getSubimage(0 *8 , 0, 8, 13);
    	 this.currentGameboard = currentGameboard;
     }
     
     public void startDisplay(int xPos, int yPos){
    	 startXPos = xPos;
    	 startYPos = yPos;
     }
     
     public void displayPlayerHealth(){
    	 int currentPlayerHealth = currentGameboard.getPlayer().getHealth();
    	 int a = currentPlayerHealth / 10;
    	 int b = currentPlayerHealth % 10;
    	 if( b == 0)
    		 b = b + 9;
    	 currentHealth1 = healthSpriteSheet.getSubimage(a * 8, 0, 8, 13);
    	 currentHealth2 = healthSpriteSheet.getSubimage(b * 8, 0, 8, 13);
     }
    
     public void displayEnemyHealth(){
    	 //@TODO need to be fixed some bugs for display the right number eg. < 15. null pointer.
    	 int currentEnemieHealth = currentGameboard.getEnemy().getHealth();
    	 int a = currentEnemieHealth / 10;
    	 int b = currentEnemieHealth % 10;
    	 if( b == 0)
    		 b = b + 10;
    	 if( a == 0)
    		 a = a + 10;
    	 if( a >= 0 && b >= 0 ){
    	    currentHealth1 = healthSpriteSheet.getSubimage((a-1) * 11, 0, 11, 20);
    	    currentHealth2 = healthSpriteSheet.getSubimage((b-1) * 11, 0, 11, 20);
    	 }
     }
     
     public void paintRequest(Graphics2D clone){
    	 clone.drawImage(currentHealth1, 42 *startXPos ,     42*startYPos + 77,null);
    	 clone.drawImage(currentHealth2, 42 *startXPos + 8,  42*startYPos + 77,null); 
     }
}
